
import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_demo/home/home_page.dart';
import 'package:flutter_demo/home/webview_page.dart';
import 'package:flutter_demo/login/login_router.dart';
import 'package:flutter_demo/message/message_router.dart';
import 'package:flutter_demo/my/my_router.dart';
import 'package:flutter_demo/point/point_router.dart';
import 'package:flutter_demo/routers/404.dart';
import 'package:flutter_demo/routers/router_init.dart';
import 'package:flutter_demo/scene/scene_router.dart';


class Routes{
  static String home = '/home';
  static String webViewPage = '/webview';

  static List<IRouterProvider> _listRouter = [];

  //配置路由
  static void configureRoutes(Router router){

    //配置路由错误跳转返回页
    router.notFoundHandler = Handler(
      handlerFunc: (BuildContext context,Map<String,List<String>> params){
        debugPrint('未找到目标页');
        return WidgetNotFound();
      }
    );

    //首页路由
    router.define(home,handler: Handler(
      handlerFunc: (BuildContext context,Map<String,List<String>> params) => Home()
    ));

    //WebView统一路由
    router.define(webViewPage, handler: Handler(
      handlerFunc: (_,parmas){
        String title = parmas['title']?.first;
        String url = parmas['url']?.first;
        return WebViewPage(title: title, url: url);
      }
    ));

    //路由初始化
    _listRouter.clear();

    //各自路由由各自模块管理，统一在此添加初始化
    //点位
    _listRouter.add(PointRouter());
    //现场
    _listRouter.add(SceneRouter());
    //消息
    _listRouter.add(MessageRouter());
    //我的
    _listRouter.add(MyRouter());
    //Login
    _listRouter.add(LoginRouter());

    //初始化路由
    _listRouter.forEach((routerProvider){
      routerProvider.initRouter(router);
    });
  }

}